package com.charles.seckillcommon.core.domain;

import java.io.Serializable;

/**
 * @author Charles-H
 * 
 * 服务内部响应码
 */
public class R<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    public static final Integer SUCCESS = 200;

    public static final Integer FAIL = 500;

    private Integer code;

    private String msg;

    private T data;

    public static <T> R<T> success() {
        return result(SUCCESS, null, null);
    }

    public static <T> R<T> success(String msg) {
        return result(SUCCESS, msg, null);
    }

    public static <T> R<T> success(T data) {
        return result(SUCCESS, null, data);
    }

    public static <T> R<T> success(String msg, T data) {
        return result(SUCCESS, msg, data);
    }

    public static <T> R<T> fail() {
        return result(FAIL, null, null);
    }

    public static <T> R<T> fail(String msg) {
        return result(FAIL, msg, null);
    }

    public static <T> R<T> fail(T data) {
        return result(FAIL, null, data);
    }

    public static <T> R<T> fail(Integer code, String msg) {
        return result(code, msg, null);
    }

    public static <T> R<T> fail(String msg, T data) {
        return result(FAIL, msg, data);
    }

    public static <T> R<T> result(Integer code, String msg, T data) {
        R<T> result = new R<>();
        result.setCode(code);
        result.setMsg(msg);
        result.setData(data);
        return result;
    }

    public static Integer getSUCCESS() {
        return SUCCESS;
    }

    public static Integer getFAIL() {
        return FAIL;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
